﻿using System;
using System.Collections.Generic;
using System.Threading;

namespace _049_使用线程锁
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 4; i++)
            {
                Thread 删除操作 = new Thread(()=> {
                    while (true)
                    {
                        lock(字段列表)
                        { 
                        if (字段列表.Count == 0)
                            break;
                        Thread.Sleep(15);
                        字段列表.RemoveAt(0);
                        Console.WriteLine($"列表中剩余元素 {字段列表.Count}个");
                    }
                    }
                });
                删除操作.Start();
            }


        }

        static List<int> 字段列表 = new List<int>()
        {
            100,105,108,113,265,970,160,
            410,303,302,104,103,102,921,
            500,501,521,522,210,211,212,
            213,214,175,376
        };
    }
}
